﻿@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@model EntityList<WorkTask>
@{
    Layout = "~/Views/Shared/_Ace_Layout.cshtml";

    var page = ViewBag.Page as Pager;
}
<div class="panel panel-default">
    <div class="panel-body">
        @Html.Partial("_List_Toolbar")
    </div>
    <div class="table-responsive">
        <table class="table table-bordered table-hover table-striped table-condensed">
            <thead>
                <tr>
                    <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("ID"))">编号</a></th>
                    <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Name"))">任务名称</a></th>
                    <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Score"))">积分</a></th>
                    <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Priority"))">优先级</a></th>
                    <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Status"))">状态</a></th>
                    <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Progress"))">进度</a></th>
                    <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("MasterID"))">负责人</a></th>
                    <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("PlanStartTime"))">计划开始</a></th>
                    <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("PlanEndTime"))">计划结束</a></th>
                    <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("PlanCost"))">工作日</a></th>
                    <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("StartTime"))">开始时间</a></th>
                    <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("UpdateUserName"))">更新人</a></th>
                    <th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("UpdateTime"))">更新时间</a></th>
                    <th class="text-center">子任务</th>
                    <th class="text-center">操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var entity in Model)
                {
                    var cls = "";
                    switch (entity.TaskStatus)
                    {
                        case TaskStatus.计划:
                        case TaskStatus.进行中:
                            switch (entity.TaskPriority)
                            {
                                case TaskPriorities.空闲:
                                    break;
                                case TaskPriorities.低级:
                                    break;
                                case TaskPriorities.普通:
                                    break;
                                case TaskPriorities.高级:
                                    cls = "alert-success";
                                    break;
                                case TaskPriorities.实时:
                                    cls = "alert-danger";
                                    break;
                                default:
                                    break;
                            }
                            break;
                        case TaskStatus.暂停:
                            cls = "alert-warning";
                            break;
                        case TaskStatus.取消:
                            cls = "alert-danger";
                            break;
                        case TaskStatus.完成:
                            cls = "alert-success";
                            break;
                        default:
                            break;
                    }
                    <tr class="alert @cls" role="alert">
                        <td class="text-center hidden-md hidden-sm hidden-xs">@entity.ID</td>
                        <td>
                            @if (ViewContext.RouteData.Values["action"].ToString().EqualIgnoreCase("Show"))
                            {
                                var title = entity.Parent == null ? "" : ("父任务：" + entity.Parent.Name);
                                if (entity.ChildCount == 0)
                                {
                                    <span title="@title">@Html.Raw(entity.Name)</span>
                                }
                                else
                                {
                                    <a href="@Url.Action("Index",new { id = entity.ID })" title="@title">@Html.Raw(entity.Name)</a>
                                }
                            }
                            else
                            {
                                if (entity.ChildCount == 0)
                                {
                                    @Html.Raw(entity.TreeNodeText)
                                }
                                else
                                {
                                    <a href="@Url.Action("Index",new { id = entity.ID })">@Html.Raw(entity.TreeNodeText)</a>
                                }
                            }
                        </td>
                        <td class="text-center">
                            @if (entity.ParentID != 0 && entity.Percent > 0)
                            {
                                <text></text>@entity.Percent<text>%, </text>
                            }
                            @entity.Score
                        </td>
                        <td class="text-center">@entity.TaskPriority</td>
                        <td class="text-center">@entity.TaskStatus</td>
                        <td class="text-center">@entity.Progress<text>%</text></td>
                        <td>@entity.MasterName</td>
                        <td class="hidden-md hidden-sm hidden-xs">@entity.PlanStartTime.ToString("yyyy-MM-dd", "")</td>
                        <td class="hidden-md hidden-sm hidden-xs">@entity.PlanEndTime.ToString("yyyy-MM-dd", "")</td>
                        <td class="text-center hidden-md hidden-sm hidden-xs">@entity.PlanCost</td>
                        <td class="hidden-md hidden-sm hidden-xs">@entity.StartTime.ToFullString("")</td>
                        <td class="hidden-md hidden-sm hidden-xs">@entity.UpdateUserName</td>
                        <td class="hidden-md hidden-sm hidden-xs">@entity.UpdateTime.ToFullString("")</td>
                        <td class="text-center">
                            @entity.ChildCount 个 @Html.ActionLink("添加", "Add", new { ParentID = entity.ID })
                        </td>
                        @if (ManageProvider.User.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                        {
                            <td class="text-center">
                                @Html.Partial("_List_Data_Action", entity)
                            </td>
                        }
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="panel-footer">
        <p>
            @Html.Partial("_List_Pager")
        </p>
    </div>
</div>